package com.ruoyi.web.controller.mxerp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MxSupplier;
import com.ruoyi.system.service.IMxSupplierService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供货商Controller
 *
 * @author ruoyi
 * @date 2024-08-11
 */
@RestController
@RequestMapping("/mxerp/supplier")
public class MxSupplierController extends BaseController {
    @Autowired
    private IMxSupplierService mxSupplierService;



    /**
     * 查询供货商列表
     */
    // @PreAuthorize("@ss.hasPermi('mxerp:supplier:alllist')")
    @PostMapping("/alllist")
    public AjaxResult alllist(){
        //startPage();
        List<JSONObject> list = mxSupplierService.allList();
        return success(list);
    }

    /**
     * 查询供货商列表
     */
    @PreAuthorize("@ss.hasPermi('mxerp:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(MxSupplier mxSupplier)
    {
        startPage();
        List<MxSupplier> list = mxSupplierService.selectMxSupplierList(mxSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供货商列表
     */
    @PreAuthorize("@ss.hasPermi('mxerp:supplier:export')")
    @Log(title = "供货商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MxSupplier mxSupplier)
    {
        List<MxSupplier> list = mxSupplierService.selectMxSupplierList(mxSupplier);
        ExcelUtil<MxSupplier> util = new ExcelUtil<MxSupplier>(MxSupplier.class);
        util.exportExcel(response, list, "供货商数据");
    }

    /**
     * 获取供货商详细信息
     */
    @PreAuthorize("@ss.hasPermi('mxerp:supplier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mxSupplierService.selectMxSupplierById(id));
    }

    /**
     * 新增供货商
     */
    @PreAuthorize("@ss.hasPermi('mxerp:supplier:add')")
    @Log(title = "供货商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MxSupplier mxSupplier)
    {
        return toAjax(mxSupplierService.insertMxSupplier(mxSupplier));
    }

    /**
     * 修改供货商
     */
    @PreAuthorize("@ss.hasPermi('mxerp:supplier:edit')")
    @Log(title = "供货商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MxSupplier mxSupplier)
    {
        return toAjax(mxSupplierService.updateMxSupplier(mxSupplier));
    }

    /**
     * 删除供货商
     */
    @PreAuthorize("@ss.hasPermi('mxerp:supplier:remove')")
    @Log(title = "供货商", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mxSupplierService.deleteMxSupplierByIds(ids));
    }
}
